#!/usr/bin/python
'''
Finds if hits in a psl file are at end of contig.
'''
import sys
import os

# parameters.
in_file = sys.argv[1]

# loop over file.
fin = open(in_file, "rb")
for line in fin:	
	# Parse.
	tmp = line.split("\t")
	if len(tmp) != 21 or tmp[0] == "match": continue
	if tmp[9] != "SMART_primer": continue
	
	# See where in seq it hit.
	tlen = int(tmp[14])
	tstart = int(tmp[15])
	tstop = int(tmp[16])
	
	srt = sorted([tstart,tstop])
	
	# See which end its closer too.
	sdist = srt[0]
	edist = tlen - srt[1]
	
	# left side.
	if sdist < edist:
		if sdist < 20:
			print sdist
	else:
		if edist < 20:
			print edist
		
	
	#sys.exit()
fin.close()
